﻿#region using
using System;
using System.Drawing;
using RRRSRoguelike.Enums;
using RRRSRoguelike.Helpers;
using RRRSRoguelike.Helpers.Visualizer;
using RRRSRoguelike.Managers;
#endregion

namespace RRRSRoguelike.Screens
{
	/// <summary>
	/// Manages the UI to handle quiting the game.
	/// </summary>
	class RuleSetScreen : Screen
	{
		
		#region variables
		MenuPanel MainPanel;
		bool quit;
		bool showMenu = true;
		Menu menu;
		#endregion
		
		#region constructor
		public RuleSetScreen()
		{
			PanelList.Add(new MenuPanel(new Point(4, 3),
			                            Visualizer.GetScreenWidth() - 9, Visualizer.GetScreenHeight() - 6));

			MainPanel = (MenuPanel)PanelList[0];
			
			menu = MainPanel.Menu;
		}
		#endregion
		
		#region methods
		/// <summary>
		/// Returning true will quit the current game.
		/// </summary>
		/// <returns></returns>
		public bool ShowYesNo()
		{

			quit = false;
			
			Show();

			return quit;
		}

		public override void Show()
		{
			Clear();
			
			//The following are necessary for the menu.
			SetupMenu(menu);
			MainPanel.Draw();
			MainPanel.DrawMenu();
			while(showMenu)
				MainPanel.HandleInput();
			
			ApplicationManager.Instance.SoundManager.PlaySound(SoundList.Pluck.ToString());
		}
		
		void SetupMenu(Menu menu)
		{
			//HACK: should be a Properties.String
			//HACK: rulesets hardcoded for now.
			menu.Add(new MenuItem("Vanilla", SelectVanilla));
			menu.Add(new MenuItem("Exit", SelectExit));
		}
		
		#endregion
		
		#region delegates

		//Event method

		void SelectVanilla(object sender, EventArgs e)
		{
			Properties.Settings.Default.RuleSet = "Vanilla";
			Properties.Settings.Default.Save();
			ReturnToOptions();
		}
		
		void SelectExit(object sender, EventArgs e)
		{

			ReturnToOptions();
		}

		void ReturnToOptions()
		{
			quit = true;
			showMenu = false;
			ApplicationManager.Instance.ScreenStack.Push(new OptionsScreen());
		}
		
		#endregion
		
	}
}
